// i2c interrupt service
#INT_SSP HIGH
void ssp_interupt ()
{
    BYTE incoming, state;

    state = i2c_isr_state();

    if(state <= 0x80)                     //Master is sending data
    {
        incoming = i2c_read();
#if (2 == I2C_ADR_SIZE)
        if(state == 1)                     //First received byte is address
            address_ = incoming << 8;
        if(state == 2)                     //First received byte is address
            address_ |= incoming;
        if(state == 3)                     //Second received byte is data
            buffer_in[address_] = incoming;
#else
        if(state == 1)                     //First received byte is address
            address_ = incoming;
        if(state == 2)                     //Second received byte is data
            buffer_in[address_] = incoming;
#endif
    }

    if(state == 0x80)                     //Master is requesting data
    {
        i2c_write(buffer_out[address_]);
    }
}

